home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / Apps / DevTools / eText5 / Source / Kludges.subproj / _FormatWritingImageView.m < prev    next >
Encoding:
Text File  |  1994-07-22  |  2.1 KB  |  88 lines

  1. /*  _FormatWritingImageView.m (Formerly ImageView.m)
  2.  *  Purpose: When a new TIFF or EPS image is opened, a window is created and
  3.  *     an instance of this class -- ImageView -- is installed as the contentView
  4.  *     for the window.  This ties the NXImage instance together with the view.
  5.  *
  6.  *  You may freely copy, distribute, and reuse the code in this example.
  7.  *  NeXT disclaims any warranty of any kind, expressed or  implied, as to its fitness
  8.  *  for any particular use.
  9.  *
  10.  */
  11. #import "_FormatWritingImageView.h"
  12.  
  13. @implementation _FormatWritingImageView : View
  14.  
  15. + new
  16. {
  17.     static Window *win = nil;
  18.     static _FormatWritingImageView *iv = nil;
  19.     
  20.     if (!iv) {
  21.         NXRect frm = {{0.0, 0.0}, {0.0, 0.0}};
  22.  
  23.         win = [[Window alloc] initContent:&frm style:NX_PLAINSTYLE backing:NX_BUFFERED buttonMask:0 defer:NO];
  24.         [win setDepthLimit:NX_TwelveBitRGBDepth];
  25.         iv = [[_FormatWritingImageView alloc] initFrame:&frm];
  26.         [[win setContentView:iv] free]; // nuke the old one
  27.         [iv allocateGState]; // neccessary? or voodoo?
  28.     }
  29.     return iv;
  30. }
  31.  
  32. - useImage: newImage
  33. {
  34.     NXRect imageRect = {{0.0, 0.0}, {0.0, 0.0}};
  35.     
  36.     [newImage getSize:&(imageRect.size)];
  37.     [super setFrame:&imageRect];[[self window] placeWindow:&imageRect];
  38.     anImage = newImage;
  39.     return self;
  40. }
  41.  
  42. - image
  43. {
  44.     return anImage;
  45. }
  46.  
  47. - drawSelf:(NXRect *)rects :(int)rectCount
  48. {
  49.     NXPoint pt = {0.0, 0.0};
  50.     static BOOL _firstTime = 1;
  51.     
  52.     if (_firstTime) {
  53.          NXSetColor(NX_COLORBROWN);
  54.          NXRectFill(rects);
  55.         _firstTime = NO;
  56.     }
  57.     NXSetColor(NX_COLORWHITE);
  58.     NXRectFill(rects);
  59.     // is there anything we can do to force this to display in color?
  60.     [anImage composite: NX_SOVER  toPoint: &pt];
  61.     return self;
  62. }
  63.  
  64. - free
  65. {
  66.     return self;
  67. }
  68.  
  69. - dumpTIFF:(const char *)tempPath {
  70.     NXStream *memstream;
  71.     id    targetRep;
  72.  
  73.     [self lockFocus];
  74.     [self drawSelf:&frame :1];
  75.     targetRep = [[NXBitmapImageRep alloc] initData:NULL fromRect:&frame];
  76.     [self unlockFocus];
  77.     memstream = NXOpenMemory(NULL, 0, NX_READWRITE);
  78.     if (targetRep) {
  79.         [targetRep setAlpha:0];
  80.         [targetRep writeTIFF:memstream];
  81.     }
  82.     NXSaveToFile(memstream,tempPath);
  83.     NXCloseMemory(memstream, NX_FREEBUFFER);
  84.     [targetRep free];
  85.     return self;
  86. }
  87.  
  88. @end